<template>
	<view class="pages">
		<my-header bgColor="bg-gradual-blue" :isBack="true" >
			<block slot="backText">返回</block>
			<block slot="content">详情</block>
		</my-header>
        <view class="col main">
            <image class="main_img w" :src="item.main_img" mode="" />
            <view class="title w">{{item.title}}</view>
            <view class="list w">
                <view class="old_price">原价：{{item.old_price}}</view>
                <view class="old_price">返利比例：{{item.coupons}}</view>
                <view class="old_price">预计返：{{item.discount_price}}</view>
                <!-- <view class="old_price">实际价：{{item.price}}</view> -->
                <view class="item row">
                    购买链接：
                    <!-- {{item.share_url}}  -->
                    <!-- #ifdef H5 -->
                    <a class="open" :href="item.share_url" >打开链接</a>
                    <!-- #endif -->
                     <!-- #ifndef H5 -->
                    <view class="copy" @click="copy(item.share_url)">复制链接</view>
                    <view class="copy" @click="open(item.share_url)">打开链接</view>
                    <!-- #endif -->
                </view>
            </view>
        </view>
        <!-- <view class="bottom"></view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
                item:{

                }
			}
		},
		onLoad(options) {
            // options.url="https://item.jd.com/100015969840.html"
            // options.type="j"
            console.log(options);

            if (options.type=="j") {
                this.get_jd(options.url)

            }else if(options.type=="t"){
              uni.$err("暂不支持淘宝",1)
            }else if(options.id){
                this.initData(options.id)
            }else{
                this.get_jd(options.url)

            }
		},
		methods: {
            async get_jd(url){
                const res=await uni.$request({
                    url
                },"api/jd/get_shop_info")
                if (res.code==200) {
                    this.item=res.data
                } else{
                    uni.$err(res.msg)
                }
                console.log(res.data);
            },
            async initData(id){
                const res=await uni.$request({
                    id
                },"api/jd/get_goods_info")
                if (res.code==200) {
                    this.item=res.data
                } else{
                    uni.$err(res.msg)
                }
                console.log(res.data);
            },
            copy(data){
                uni.setClipboardData({
                    data,
                    success: function () {
                        console.log('success');
                    }
                });
            },
            open(url){
                console.log(url);
                 uni.navigateToMiniProgram({
                    // appId: 'wx91d27dbf599dff74',
                    appId: 'wx1edf489cb248852c',

                    path: "pages/proxy/union/union?spreadUrl=" + url,
                    extraData: {},
                    envVersion: 'release',
                    success: (res) => {
                        console.log(res);
                    },
                    fail: (err) => {
                        console.log(err);
                    },
                    complete: () => {}
       });
            }
            
		}
	}
</script>

<style lang="scss">
	@import "./detail";
</style>